package com.tubeonfire.util;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;

import com.tubeonfire.blobstore.BlobKeyProcess;
import com.tubeonfire.entity.Channel;

public class ChannelValidate {

	private static final Logger log = Logger.getLogger(ChannelValidate.class
			.getName());

	public static void checkForm(HttpServletRequest req, Channel obj) {
		try {
			String title = (String) req.getParameter("title");
			String description = (String) req.getParameter("description");
			String imgKey = BlobKeyProcess.getBlobKey(req, "image");
			if (title != null && !title.isEmpty()) {
				obj.setTitle(title);
			}
			if (description != null && !description.isEmpty()) {
				obj.setDescription(description);
			}
			if (imgKey != null && !imgKey.isEmpty()) {
				obj.setImageKey(imgKey);
			}

		} catch (IOException e) {
			log.warning(e.toString());
			e.printStackTrace();
		}
	}
}
